package com.onetech.adrewards.free.adapters;


import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.onetech.adrewards.free.R;
import com.onetech.adrewards.free.objects.SocialShareDTO;


public class ListSocialShareAdapter extends BaseAdapter {
	private class SocialViewHolder {
		public TextView title;
		public TextView description;
		public TextView bonus;
		public ImageView iconSocial;
	}

	private Activity activity;
	private List<SocialShareDTO> listSocial;
	private static LayoutInflater inflater = null;

	public ListSocialShareAdapter(Activity _activity) {
		activity = _activity;
		listSocial = new ArrayList<SocialShareDTO>();
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public void updateSocialList(List<SocialShareDTO> _listSocialDTOs) {
		listSocial.clear();
		listSocial.addAll(_listSocialDTOs);
		notifyDataSetChanged();
	}

	public void insertSocialList(List<SocialShareDTO> _listSocialDTOs) {
		listSocial.addAll(_listSocialDTOs);
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return listSocial.size();
	}

	@Override
	public SocialShareDTO getItem(int arg0) {
		if (listSocial == null) {
			return null;
		}
		return listSocial.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		SocialViewHolder viewHolder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.social_share_item_layout,
					parent, false);
			viewHolder = new SocialViewHolder();
			viewHolder.title = (TextView) convertView
					.findViewById(R.id.titleSocial);	
			viewHolder.description = (TextView) convertView
					.findViewById(R.id.descriptionSocial);	
			viewHolder.bonus = (TextView) convertView
					.findViewById(R.id.bonusSocial);	
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (SocialViewHolder) convertView.getTag();
		}
		SocialShareDTO temp = listSocial.get(position);
		viewHolder.title.setText(temp.title);
		viewHolder.description.setText(Html.fromHtml(temp.description));
		viewHolder.bonus.setText(temp.bonus+"pt");
//		ImageLoader.getInstance(activity.getApplicationContext()).DisplayImage(
//				temp.getCover(), viewHolder.cover);
		return convertView;
	}

}

